﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using lcmyjobs.Model;
using System.Data.SqlClient;
namespace lcmyjobs.BLL
{
	/// <summary>
	/// news
	/// </summary>
	public partial class news
	{
		private readonly lcmyjobs.DAL.news dal=new lcmyjobs.DAL.news();
		public news()
		{}
		#region  Method
        public DataSet GetTJ(int atid, int count)
        {
            return dal.GetTJ(atid, count);
        }
        public DataSet GetListHotNews(int atd, int count)
        {
            return dal.GetListHotNews(atd, count);
        }
        public DataSet GetListNews(int atd, int count, int typid)
        {
            return dal.GetListNews(atd, count, typid);
        }
        public DataSet GetNews(int nid)
        {
            return dal.GetNews(nid);
        }
        public int deletenews(string uid)
        {
            return dal.deletenews(uid);
        }
        public DataSet PageNews(int atid, int startid, int pagesize, out int count)
        {
            return dal.PageNews(atid, startid, pagesize, out count);
        }
        public DataSet PageNews(int atid, int startid, int pagesize,int typeid, out int count)
        {
            return dal.PageNews(atid, startid, pagesize,typeid, out count);
        }

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int nid)
		{
			return dal.Exists(nid);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
        public bool Add(SqlParameter[] parameters)
		{
			return dal.Add(parameters);
		}
         /// <summary>
        /// 批量个更改
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="value">更改值</param>
        /// <param name="where">更改条件enterprise_rid</param>
        /// <returns></returns>
        public bool UpdateWhere(string keywords, string value, string where)
        {
            return dal.UpdateWhere(keywords,value,where);
        }
         /// <summary>
        /// 批量个更改
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="value">更改值</param>
        /// <param name="where">更改条件enterprise_rid</param>
        /// <returns></returns>
        public bool UpdateWherestr(string keywords, string value, string where)
        {
            return dal.UpdateWherestr(keywords, value, where);
        }
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.news model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int nid)
		{
			
			return dal.Delete(nid);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string nidlist )
		{
			return dal.DeleteList(nidlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.news GetModel(int nid)
		{
			
			return dal.GetModel(nid);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public lcmyjobs.Model.news GetModelByCache(int nid)
		{
			
			string CacheKey = "newsModel-" + nid;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(nid);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (lcmyjobs.Model.news)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<lcmyjobs.Model.news> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<lcmyjobs.Model.news> DataTableToList(DataTable dt)
		{
			List<lcmyjobs.Model.news> modelList = new List<lcmyjobs.Model.news>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				lcmyjobs.Model.news model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new lcmyjobs.Model.news();
					if(dt.Rows[n]["nid"]!=null && dt.Rows[n]["nid"].ToString()!="")
					{
						model.nid=int.Parse(dt.Rows[n]["nid"].ToString());
					}
					if(dt.Rows[n]["ntitle"]!=null && dt.Rows[n]["ntitle"].ToString()!="")
					{
					model.ntitle=dt.Rows[n]["ntitle"].ToString();
					}
					if(dt.Rows[n]["ntime"]!=null && dt.Rows[n]["ntime"].ToString()!="")
					{
						model.ntime=DateTime.Parse(dt.Rows[n]["ntime"].ToString());
					}
					if(dt.Rows[n]["nauthor"]!=null && dt.Rows[n]["nauthor"].ToString()!="")
					{
					model.nauthor=dt.Rows[n]["nauthor"].ToString();
					}
					if(dt.Rows[n]["viewtime"]!=null && dt.Rows[n]["viewtime"].ToString()!="")
					{
						model.viewtime=int.Parse(dt.Rows[n]["viewtime"].ToString());
					}
					if(dt.Rows[n]["ncontent"]!=null && dt.Rows[n]["ncontent"].ToString()!="")
					{
					model.ncontent=dt.Rows[n]["ncontent"].ToString();
					}
					if(dt.Rows[n]["ntid"]!=null && dt.Rows[n]["ntid"].ToString()!="")
					{
						model.ntid=int.Parse(dt.Rows[n]["ntid"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

